import axios from 'axios'
import store from '@/store'
import JSONBig from 'json-bigint'

// 创建axios实例
const request = axios.create({
    baseURL: 'http://toutiao-app.itheima.net',
    transformResponse: [function (data) {
        // Do whatever you want to transform the data
        try {
            return JSONBig.parse(data)
        } catch (err) {
            return data;
        }
    }],
})

// 设置请求拦截器
request.interceptors.request.use((config) => {

    if (store.state.user) {
        config.headers.Authorization = `Bearer ${store.state.user.token}`
    }

    // console.log(config);
    return config
})

export default request